﻿<%@ WebHandler Language="C#" Class="ScriptBanner" %>

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Xml;
using CommonTagTime.ModelObject;
using CommonTagTime.Business;
using System.Text;
using CommonTagTime;
public class ScriptBanner : IHttpHandler
{

    public BannerCollection GetData()
    {
        //get Condition
        busBanner _busBanner = new busBanner();
        CommonTagTime.ModelObject.Banner objLogo = new CommonTagTime.ModelObject.Banner();
        objLogo.CurrentPage = 1;
        objLogo.OrderBy = busBanner.SortOrder;
        objLogo.OrderDirection = "ASC";
        objLogo.PageSize = int.MaxValue;
        objLogo.Condition = " b.IsActive=1";
        DateTime dtNow = clsDateTime.Now;
        objLogo.Condition += " and datediff(day,b.StartingDate,'" + clsConvert.String(dtNow) + "')>=0";
        objLogo.Condition += " and datediff(day,'" + clsConvert.String(dtNow) + "',b.EndingDate)>=0";
        return _busBanner.List(objLogo);
    }

    public void ProcessRequest(HttpContext context)
    {
        string data = GetXMLData();
        context.Response.Write(data);
        context.Response.End();

    }
    public string GetXMLData()
    {
        string result = @"
        <banner width= ""596"" height=""250""
		startWith= ""1"" 
		random= ""false""
		
		backgroundColor = ""0xffffff"" 
		backgroundTransparency = ""100""
		
		cellWidth = ""50""
		cellHeight = ""50""
		
		showMinTime = ""0.2""
		showMaxTime = ""1.5""
	
		overColor = ""0x473C31""
		normalColor = ""0x000000""
		selectedTextColor = ""0xffffff""
		
		selectedButtonAlpha = ""70""
		
		controllerVisible = ""true""
		controllerBackgroundVisible = ""true""
		
		prevNextVisible = ""true""
		playBtVisible = ""true""
		autoPlay = ""true""
		navigationButtonsColor = ""0x1a1a1a""
		
		controllerDistanceX = ""10""
		controllerDistanceY = ""10""
		
		controllerHeight = ""27""
		distanceBetweenControllerElements = ""10""
		distanceBetweenThumbs = ""3""
		
		itemNumberSize = ""12""
		
		captionY = ""10""
		captionX = ""10""			
		
		captionWidth = ""390""

		buttonText = ""read more""
		btnNormalColor = ""0xffffff""
		btnOverColor = ""0x999999""
		
		readMoreBackAlpha = ""80""
		readMoreBackColor = ""0x473C31""
		
		paddingX = ""20""
		paddingY = ""15""
		
		btnSpacingW = ""50""
		btnSpacingH = ""5""
		
		loaderColor = ""0x000000"">";
        
//        BannerCollection banners = GetData();
//        if (banners != null && banners.Count > 0)
//        {
//            foreach (CommonTagTime.ModelObject.Banner banner in banners)
//            {
//                result += @"<item>
//                        <path>/" + clsConfigData.DEFAULT_UPLOAD_BANNER_FOLDER + banner.FilePath + @"</path>
//                        <link>" + banner.Url + @"</link>
//                        <target>_blank</target>
//                        <slideShowTime>3</slideShowTime>
//                        <bar_color>0xffffff</bar_color>
//                        <bar_transparency>40</bar_transparency>
//
//                        <caption_color>0xffffff</caption_color>
//                        <caption_transparency>60</caption_transparency>
//
//                        <stroke_color>0xffffff</stroke_color>
//                        <stroke_transparency>60</stroke_transparency>
//                      </item>";
//            }
//        }
//        result += "</banner>";
        
        
        string str = string.Format(@"<?xml version=""1.0"" encoding=""UTF-8""?>
        <banner width= ""596"" height=""250""
		startWith= ""1"" 
		random= ""false""
		
		backgroundColor = ""0xffffff"" 
		backgroundTransparency = ""100""
		
		cellWidth = ""50""
		cellHeight = ""50""
		
		showMinTime = ""0.2""
		showMaxTime = ""1.5""
	
		overColor = ""0x473C31""
		normalColor = ""0x000000""
		selectedTextColor = ""0xffffff""
		
		selectedButtonAlpha = ""70""
		
		controllerVisible = ""true""
		controllerBackgroundVisible = ""true""
		
		prevNextVisible = ""true""
		playBtVisible = ""true""
		autoPlay = ""true""
		navigationButtonsColor = ""0x1a1a1a""
		
		controllerDistanceX = ""10""
		controllerDistanceY = ""10""
		
		controllerHeight = ""27""
		distanceBetweenControllerElements = ""10""
		distanceBetweenThumbs = ""3""
		
		itemNumberSize = ""12""
		
		captionY = ""10""
		captionX = ""10""			
		
		captionWidth = ""390""

		buttonText = ""read more""
		btnNormalColor = ""0xffffff""
		btnOverColor = ""0x999999""
		
		readMoreBackAlpha = ""80""
		readMoreBackColor = ""0x473C31""
		
		paddingX = ""20""
		paddingY = ""15""
		
		btnSpacingW = ""50""
		btnSpacingH = ""5""
		
		loaderColor = ""0x000000"">");
        
        BannerCollection banners = GetData();
        if (banners != null && banners.Count > 0)
        {
            foreach (Banner banner in banners)
            {
                str += string.Format(@"<item>
                    <path>/{0}</path>
                    <title></title>
		            <target>_blank</target>
		            <link>{1}</link>
		
		            <bar_color>0xffffff</bar_color>
		            <bar_transparency>40</bar_transparency>
		
		            <caption_color>0xffffff</caption_color>
		            <caption_transparency>60</caption_transparency>
		
		            <stroke_color>0xffffff</stroke_color>
		            <stroke_transparency>60</stroke_transparency>
		
		            <slideshowTime>3</slideshowTime>
	            </item>", clsConfigData.DEFAULT_UPLOAD_BANNER_FOLDER + banner.FilePath, banner.Url);
            }
        }
	
        str += "</banner>";

        return str;
    }
    public bool IsReusable
    {
        get { return false; }
    }

}
